package com.baomidou;

import com.baomidou.kaptcha.Kaptcha;
import com.baomidou.kaptcha.as;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/kaptcha")
public class KaptchaController {



    public  as ad;

    private Kaptcha kaptcha;

    public KaptchaController(as ad, Kaptcha kaptcha) {
        this.ad = ad;
        this.kaptcha = kaptcha;
    }

    @GetMapping("/render")
    public void render() {

        System.out.println(ad);
        ad.showNubmer(1);
        System.out.println(ad.addOne(1) );
        kaptcha.render();
    }

    @PostMapping("/valid")
    public void validDefaultTime(@RequestBody Code code) {



        //default timeout 900 seconds
        System.out.println(code);
        String codee = code.getCode();
        System.out.println(codee);
        kaptcha.validate(codee);
    }

    @PostMapping("/validTime")
    public void validCustomTime(@RequestParam String code) {
        kaptcha.validate(code, 60);
    }

}